#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define SIZE 1024

char buf[SIZE+1];

int main(int argc,char* argv[])
{

    if(argc == 1)
    {
        printf("LGREP: 搜索词[文件...]\n");
        return 1;
    }
    else if(argc == 2)
    {
        fgets(buf,SIZE,stdin);
        if(strstr(buf,argv[1]))
            printf("%s",buf);
        return 0;
    }
    for(int i = 2; i < argc; ++i)
    {
        FILE* fp = fopen(argv[i],"r");
        if(fp == NULL)
        {
            perror("LGREP");
            exit(1);
        }
        while(fgets(buf,SIZE,fp) != NULL)
        {
            if(strstr(buf,argv[1]))
                printf("%s",buf);
        }
    }
    return 0;
}